<%@page import="com.spreedairy.portal.service.CustomFieldLocalServiceUtil"%>
<%@ include file="/html/common/init.jsp" %>

<%
	PortletURL defineURL = renderResponse.createRenderURL();
	defineURL.setParameter("jspPage", "/html/category/define_field.jsp");
	
	String categoryId = (String)request.getParameter("categoryId");
	defineURL.setParameter("categoryId",categoryId);
	ShoppingCategory category = ShoppingCategoryLocalServiceUtil.getCategory(Long.parseLong(categoryId));
	String redirect = ParamUtil.getString(request, "redirect");
	
	 List<CustomField>  customFields= null;
	try{
		customFields = (List)CustomFieldLocalServiceUtil.findByCategoryId(Long.parseLong(categoryId));
		}catch(Exception e){
			
		} 
%>

<%
	long parentCategoryId = BeanParamUtil.getLong(category, request, "parentCategoryId", ShoppingCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);
	
	String parentCategoryName = "";
	
	try {
		ShoppingCategory parentCategory = ShoppingCategoryLocalServiceUtil.getCategory(parentCategoryId);
	
		parentCategoryName = parentCategory.getName();
	}
	catch (NoSuchCategoryException nscce) {
	}

%>

<portlet:actionURL name="updateProcess" var="editCategoryURL">
	<portlet:param name="<%= Constants.CMD %>" value="<%= Constants.DELETE %>" />
</portlet:actionURL>

<liferay-portlet:renderURL varImpl="cancelURL"></liferay-portlet:renderURL>

<aui:form action="<%= editCategoryURL %>" method="post" name="fm" >

<aui:model-context bean="<%= category %>" model="<%= ShoppingCategory.class %>" />
	<aui:input name="DelCategory" type="hidden" value="DelCategory" />
	<aui:input name="redirect" type="hidden" value="<%= redirect %>" />
	
	<aui:input name="categoryId" type="hidden" value="<%= categoryId %>" />
	<liferay-ui:header backURL="<%= redirect %>" title="category"/>
	
	<aui:fieldset>
		<h5><span style="color:#354789">ParentCategory : </span></h5>
		
		<c:if test="<%= parentCategoryName == null %>">
			<h5><span style="color:#354789"> Select ParentCategory </span></h5>
		</c:if>
		
		<aui:a href="#" id="parentCategoryName" label="<%= parentCategoryName %>" />
		<aui:input cssClass="lfr-input-text-container" name="name" label="Category Name" type="text" readonly="true"/>
		<aui:input cssClass="lfr-textarea-container" name="description" type="textarea" readonly="true"/>
		
		<h5><span style="color:#354789">Defined Fields </span></h5>
		
		<liferay-ui:search-container emptyResultsMessage="there-are-no-fields" delta="5">
		
			<liferay-ui:search-container-results>
			<%
				/* results = ListUtil.subList(customFields, searchContainer.getStart(),searchContainer.getEnd());
				total = customFields.size();
				pageContext.setAttribute("results", results);
				pageContext.setAttribute("total", total); */
			%>
			</liferay-ui:search-container-results>
			
			<liferay-ui:search-container-row className="com.spreedairy.portal.model.CustomField" keyProperty="recId" modelVar="CustomField">
				<liferay-ui:search-container-column-text name="KeyValue" property="keyValue"/>
				<liferay-ui:search-container-column-text name="KeyType" property="keyType"/>
				<liferay-ui:search-container-column-text name="Optional" property="optional"/>
				<liferay-ui:search-container-column-text name="OptionsValue" property="optionsValue"/>
			</liferay-ui:search-container-row>
			
			<liferay-ui:search-iterator></liferay-ui:search-iterator>
			
		</liferay-ui:search-container>
		
		<c:if test="<%= category == null %>">
			<aui:field-wrapper label="permissions">
				<liferay-ui:input-permissions
					modelName="<%= ShoppingCategory.class.getName() %>"
				/>
			</aui:field-wrapper>
		</c:if>
	</aui:fieldset>
	
	<aui:button-row>
		<input type="button" name="EDIT" value="Edit" onClick="location.href='<%= defineURL.toString()+"&categoryId="+categoryId %>'"/>
		
		<aui:button type="submit" name="Delete" value="Delete"/>
		
		<c:if test="<%= customFields.size() == 0 %>">
			<input onClick="location.href='<%= defineURL.toString() %>'" type="button" value="Define Fields" />
		</c:if>
		
		<aui:button onClick="<%= cancelURL.toString() %>" type="button" value="Cancel" />
	</aui:button-row>
	
</aui:form>